//
//  WdModel.swift
//  GjCup
//
//  Created by abc on 2024/4/7.
//

import UIKit
enum WdType: Int {
    case C = 0  // 摄氏度
    case H = 1  // 华氏度
    case K      // 开氏度
    case L      // 兰氏度
    case Lie    // 列氏度
}

class WdModel: NSObject {
    
    let wdTypes = ["摄氏度","华氏度","开氏度","兰氏度","列氏度"]
    let wdSigns = ["°C","℉","K","°R","°Re"]
    /// 摄氏度互转华氏度
    func sToH(s: Float, reverse: Bool = false) -> Float{
        var h: Float = 0
        if reverse {
            h = (s - 32) / 1.8
        }else{
            h = (s * 1.8) + 32
        }
        return h
    }
    /// 摄氏度互转开氏度
    func sToK(s: Float, reverse: Bool = false) -> Float {
        var h: Float = 0
        if reverse {
            h = s - 273.15
        }else{
            h = s + 273.15
        }
        return h
    }
    /// 摄氏度互转兰氏度
    func sToL(s: Float, reverse: Bool = false) -> Float {
        var h: Float = 0
        if reverse {
            h = s * 5 / 9 - 273.15
        }else{
            //摄氏度+273.15）×9/5
            h = (s + 273.15) * 9 / 5
        }
        return h
    }
    /// 摄氏度互转列氏度
    func sToLie(s: Float, reverse: Bool = false) -> Float  {
        var h: Float = 0
        if reverse {
            h = s * 1.25
        }else{
            h = s / 1.25
        }
        return h
    }
    
    
    func allChange(t: Float, type: WdType) -> [String]  {
        var s = t
        switch type {
            case .C:
                break
            case .H:
                s = sToH(s: t, reverse: true)
                break
            case .K:
                s = sToK(s: t, reverse: true)
                break
            case .L:
                s = sToL(s: t, reverse: true)
                break
            case .Lie:
                s = sToLie(s: t, reverse: true)
                break
        }
        return ["\(s)\(wdSigns[0])","\(sToH(s: s))\(wdSigns[1])","\(sToK(s: s))\(wdSigns[2])","\(sToL(s: s))\(wdSigns[3])","\(sToLie(s: s))\(wdSigns[4])"]
    }
    

}
